<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
	 	<title>登录</title>
        <link rel="stylesheet" type="text/css" href="css/login_style.css" />
    </head>
    <body>
        <div class="container">
            <header>
                <h1 class="color" style="font-size: 40px">
                    顶岗实习管理系统
                </h1>
				<nav class="codrops-demos">
					<span>Management of replacement internship System</span>
				</nav>
            </header>
            <section>				
                <div id="container_demo" >
                    <a class="hiddenanchor" id="toregister"></a>
                    <a class="hiddenanchor" id="tologin"></a>
                    <div id="wrapper">
                        <div id="login" class="animate form border_color">
                            <form  action="#" autocomplete="on"> 
                                <h1 style="font-size: 35px">登录</h1>
                                <p class="posotion">
                                    <label for="username" class="uname">账号 </label>
                                    <span class=" iconfont icon_zhanghao"></span>
                                    <input type="text" placeholder="账号"  id="loginname"/>
                                </p>
                                <p class="posotion">
                                    <label for="password" class="youpasswd"> 密码</label>
                                    <span class=" iconfont icon_mima"></span>
                                    <input type="password" placeholder="密码"  id="password" />
                                </p>
                                <p class="posotion">
                                    <label for="password" class="yanzhengma"> 验证码 </label>
                                    <span class=" iconfont icon_yanzhengma"></span>
                                    <input type="text" id="J_codetext" placeholder="验证码" maxlength="4"  class="login_txtbx" >
                                    <canvas class="J_codeimg" id="myCanvas" onclick="createCode()" style="float: right;width:30%;border: 1px solid #b2b2b2;height:38px;margin-top: 4px;border-radius: 3px;">对不起，您的浏览器不支持canvas，请下载最新版浏览器!</canvas>
                                    <!--<input type="text"  placeholder="验证码" maxlength="4" class="login_txtbx" >-->
                                </p>
                                <p class="keeplogin">
                                    <span>
                                        <input type="radio"  name="role"  value="1"  />
                                        <label for="loginkeeping">管理员</label>
                                    </span>
                                <span>
                                    <input type="radio"name="role"  value="2"  />
                                    <label for="loginkeeping">老师</label>
                                </span>
                                <span>
                                    <input type="radio" name="role"  value="3"  />
                                    <label for="loginkeeping">学生</label>
                                </span>
                               <!--  <span>
                                    <input type="radio" name="role"  value="4"  />
                                    <label for="loginkeeping">企业</label>
                                </span> -->
								</p>
                                <p class="login button"> 
                                    <input type="button" onclick="severCheck();" value="登录" style="font-family: 'Arial Narrow' !important;"/>
								</p>
                                <p class="change_link" style="text-align: center">
                                    © 2016 合肥正鼎软件科技有限公司 版权所有
								</p>
                            </form>
                        </div>
                    </div>
                </div>  
            </section>
        </div>
    </body>
 <script type="text/javascript" src="assets/js/jquery-1.10.2.min.js"></script>
<script src="js/verificationNumbers.js"></script>
<script type="text/javascript" src="js/jquery.tips.js"></script>
<script type="text/javascript" src="assets/js/jquery.cookie.js"></script>
<script type="text/javascript" src="layer/layer.js" ></script>
<script src="js/Particleground.js"></script>
<script>
var ua = navigator.userAgent;
var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
    isIphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
    isAndroid = ua.match(/(Android)\s+([\d.]+)/),
    isMobile = isIphone || isAndroid;
    if(isMobile) {
    	window.location.href="<%=basePath%>student/m_login.do";
    }
  //验证码
  createCode();
  //测试提交，对接程序删除即可
  /* $(".submit_btn").click(function(){
	  location.href="main.html";
	}); */
jQuery(function() {
	var loginname = $.cookie('loginname');
	var password = $.cookie('password');
	var role = $.cookie('role');
	var type = $.cookie('type');
	if (typeof(loginname) != "undefined"
			&& typeof(password) != "undefined") {
		$("#loginname").val(loginname);
		$("#password").val(password);
		$("#role").val(role);
		$("#saveid").attr("checked", true);
		if(type==1){
			 $("input[name='type']:eq(1)").attr("checked","checked");
		}
	}
});
function severCheck(){
	  var inputCode = document.getElementById("J_codetext").value.toUpperCase();
	    var codeToUp=code.toUpperCase();
	    if(inputCode.length <=0) {
	    	$("#J_codetext").tips({
				side : 2,
				msg : '验证码不得为空',
				bg : '#AE81FF',
				time : 3
			});

	      createCode();
	      return false;
	    }
	    else if(inputCode != codeToUp ){
	      document.getElementById("J_codetext").value="";
	      $("#J_codetext").tips({
				side : 2,
				msg : '验证码错误',
				bg : '#AE81FF',
				time : 3
			});
	      createCode();
	      return false;
	    } else { 
	if(check()){
		var loginname = $("#loginname").val();
		var password = $("#password").val();
		var role = loginname+",zt,"+password+",zt,"+$("input[name='role']:checked").val();
		$.ajax({
			type: "POST",
			url: 'admin/login.do',
	    	data: {KEYDATA:role},
			dataType:'json',
			cache: false,
			success: function(data){
				if("success" == data.result){
					saveCookie();
					window.location.href="admin/index.do";
				}else if("usererror" == data.result){
					$("#loginname").tips({
						side : 1,
						msg : "用户名或密码有误",
						bg : '#FF5080',
						time : 5
					});
					$("#loginname").focus();
				}  else if("nullrole" == data.result){
					layer.alert('请选择角色!', {
			            skin: 'layer-ext-moon' 
			        });
				}
			}
		});
		} 
}
	    }
//客户端校验
function check() {
	if ($("#loginname").val() == "") {
		$("#loginname").tips({
			side : 2,
			msg : '帐号不得为空',
			bg : '#AE81FF',
			time : 3
		});

		$("#loginname").focus();
		return false;
	} else {
		$("#loginname").val(jQuery.trim($('#loginname').val()));
	}

		if ($("#password").val() == "") {

			$("#password").tips({
				side : 2,
				msg : '密码不得为空',
				bg : '#AE81FF',
				time : 3
			});

			$("#password").focus();
			return false;
		}
		return true;
	}

	function savePaw() {
		if (!$("input[type='checkbox']").is(':checked')) {
			$.cookie('loginname', '', {
				expires : -1
			});
			$.cookie('password', '', {
				expires : -1
			});
			$("#loginname").val('');
			$("#password").val('');
		}
	}
	function saveCookie() {
		if ($("input[type='checkbox']").is(':checked')) {
			$.cookie('loginname', $("#loginname").val(), {
				expires : 7
			});
			$.cookie('password', $("#password").val(), {
			expires : 7
		});
		$.cookie('type', $("input[name='type']:checked").val(), {
			expires : 7
		});
	}
}
//TOCMAT重启之后 点击左侧列表跳转登录首页 
if (window != top) {
	top.location.href = location.href;
}
</script>
</html>
